<?php

use mdm\admin\AnimateAsset;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\helpers\Json;
use yii\web\YiiAsset;

/* @var $this yii\web\View */
/* @var $model mdm\admin\models\Assignment */
/* @var $fullnameField string */

$userName = $model->{$usernameField};
if (!empty($fullnameField)) {
    $userName .= ' (' . ArrayHelper::getValue($model, $fullnameField) . ')';
}
$userName = Html::encode($userName);

$this->title = Yii::t('rbac-admin', 'Assignment') . ' : ' . $userName;

$this->params['breadcrumbs'][] = ['label' => '管理员列表', 'url' => ['/admin-user/index']];
$this->params['breadcrumbs'][] = $userName;

AnimateAsset::register($this);
YiiAsset::register($this);
$opts = Json::htmlEncode([
    'items' => $model->getItems(),
]);
$this->registerJs("var _opts = {$opts};");
$this->registerJs($this->render('_script.js'));
$animateIcon = ' <i class="glyphicon glyphicon-refresh glyphicon-refresh-animate"></i>';
?>
<style>
    input.form-control{
        border-radius: 4px;
        margin-bottom: 10px;
        height: 32px;
    }
    @media (min-width: 768px){
        .form-inline .form-control {
            display: block;
            width: 100%;
        }
    }
    .form-inline div.col-sm-1 {
        text-align: center;
    }
    .form-inline .form-control {
        margin-bottom: 5px;
    }
</style>
<div class="row">
    <div class="col-xs-12">
        <div class="box">
            <div class="box-header with-border">
                <h3 class="box-title"><?= Html::encode($this->title) ?></h3>
            </div>
            <div class="box-tools form-inline">
                <div class="box-body assignment-index">
    <div class="row">
        <div class="col-sm-12">
            <div class="col-sm-5">
                <input class="form-control search" data-target="available"
                       placeholder="<?=Yii::t('rbac-admin', 'Search for available');?>">
                <select multiple size="20" class="form-control list" data-target="available">
                </select>
            </div>
            <div class="col-sm-1">
                <br><br>
                <?=Html::a('&gt;&gt;' . $animateIcon, ['assign', 'id' => (string) $model->id], [
        'class' => 'btn btn-success btn-assign',
        'data-target' => 'available',
        'title' => Yii::t('rbac-admin', 'Assign'),
    ]);?><br><br>
                <?=Html::a('&lt;&lt;' . $animateIcon, ['revoke', 'id' => (string) $model->id], [
        'class' => 'btn btn-danger btn-assign',
        'data-target' => 'assigned',
        'title' => Yii::t('rbac-admin', 'Remove'),
    ]);?>
            </div>
            <div class="col-sm-5">
                <input class="form-control search" data-target="assigned"
                       placeholder="<?=Yii::t('rbac-admin', 'Search for assigned');?>">
                <select multiple size="20" class="form-control list" data-target="assigned">
                </select>
            </div>
        </div>
    </div>
</div>
</div>
